<?php
/*
通用分类
*/
//define('Acache_no','1');
class Con_setting extends Acan{
	public $defaultAct='manage';
	public $Conread = '管理';
	public $Actread = array('manage'=>'配置管理','save'=>'保存','del'=>'删除','delall'=>'删除所有');
	function __construct($ainfo=null){
		parent::__construct($ainfo=null);
		if(empty($this->id) || $this->id == '*'){$this->id = '0';}
		$this->model = Afun_db()->model(Acan_table_option);
		$this->atitle = $this->Actread[$this->Aact];
	}
	//--用户管理
	function Act_manage(){
		$obj = Afun_acan_new('list');
		$key_name = $this->model->key_name;
		$columnrr = $this->model->comment;//初始栏目
		unset($columnrr['appid']);//密码栏目不显示
		$column = $obj->column($this->model,$columnrr,$_POST['acolumn']);
		$column_html = $obj->column_html($this->model,$column,'Aform');
		$column_json = $obj->form_json($this->model);
		//分页函数
		$con->where = "1 and appid=".Acan_app_id;
		$con->select = "a.*";
		$page->theurl = $this->Aactr.'-'.$this->id;
		$page->by = $this->model->key_name;
		$page->page = '20';
		$page->counts = $this->model->count($con);	//统计总数目
		$pages = Afun_apage($page);
		$con->order = "a.$pages->orderby";
		$con->limit = $pages->limit;
		//分页结束
		$list = $this->model->findAll($con);
		include $this->Atpl();
	}
	//--浏览设置
	function Act_view(){
		if($this->id>0){
			$info = $this->model->ofindPk($this->id);
		}
		include $this->Atpl();
	}
	function Act_add(){
		$arr = array(
			'site'=>array(
				array('key'=>'Acan_site_logo','title'=>'LOGO','value'=>'/images/logo/nice9s.png'),
				array('key'=>'Acan_site_email','title'=>'站点邮箱','value'=>'abans@qq.com'),
				array('key'=>'Acan_site_domain','title'=>'站点域名','value'=>'nice9s.com'),
				array('key'=>'Acan_site_name','title'=>'站点名称','value'=>'Acan'),
				array('key'=>'Acan_site_url','title'=>'站点网址','value'=>''),
				array('key'=>'Acan_site_icp','title'=>'备案号','value'=>'')
			),
			'mail'=>array(
				array('key'=>'Acan_email_user','title'=>'邮箱地址','value'=>'mail.nice9s.com'),
				array('key'=>'Acan_email_pass','title'=>'邮箱密码','value'=>'123456'),
				array('key'=>'Acan_email_smtp','title'=>'SMTP服务器','value'=>'smtp.nice9s.com'),
				array('key'=>'Acan_email_port','title'=>'SMTP端口','value'=>'25'),
				array('key'=>'Acan_email_frommail','title'=>'发送邮箱','value'=>'from@nice9s.com'),
				array('key'=>'Acan_email_fromname','title'=>'发送名称','value'=>'nice9s'),
				array('key'=>'Acan_email_replymail','title'=>'回复邮箱','value'=>'reply@nice9s.com'),
				array('key'=>'Acan_email_replyname','title'=>'回复名称','value'=>'nice9s'),
				array('key'=>'Acan_email_pop','title'=>'POP服务器','value'=>'pop.nice9s.com'),
				array('key'=>'Acan_email_pport','title'=>'POP端口','value'=>'110')
			)
		);
		$op = Afunc_option();
		if(is_array($arr[$this->id]))
			foreach ($arr[$this->id] as $k => $v) {
				if(!$op->get($v['key'])){
					$op->set($v['value'],$v['title']);
				}
			}
		Afun_refresh("初始化成功",'referrer');
	}
	//--获取单条信息
	function Act_info(){
		if($this->id<1){
			return;
		}
		$info = $this->model->ofindPk($this->id);
		Afun_json($info);
	}
	//批量更新
	function Act_save(){
		Afun_post_auth();
		$savedata = $_POST['save'];
		if($this->id == 'one'){
			$key = $savedata[$this->model->key_name];
			unset($savedata[$this->model->key_name]);
			if(!empty($key)){
				$msg = $this->model->updatePk($savedata,$key);
			}else{//--添加一个新用户
				$savedata['appid'] = Acan_app_id;
				$msg = $this->model->save($savedata);
			}
			if(empty($savedata['key'])){
				$oinfo = $this->model->ofindPk($key);
				$keys = $oinfo->key;
			}else{
				$keys = $savedata['key'];
			}
			Afunc_option($keys)->delcache();
		}elseif(is_array($savedata)){
			foreach($savedata as $i=>$vals){
				$this->model->updatePk($vals,$vals['key']);
				Afunc_option($vals['key'])->delcache();
			}
		}
		Afun_json($msg);
	}
	//删除
	function Act_del(){
		Afun_post_auth();
		if($this->model->deletePk($this->id)){
			Afunc_group()->usergroupdel($this->id);
			echo '删除成功';
		}
	}
	//删除所选
	function Act_delall(){
		Afun_post_auth();
		foreach($_POST['chk'] as $key=>$val){
			Afunc_group()->usergroupdel($val);
			if(empty($vala))
				$vala = "'$val'";
			else
				$vala .=",'$val'";
		}
		$this->model->delete($this->model->key_name." IN ($vala)");
		Afun_refresh("删除成功",'referrer');
	}
	

}

?>